package com.huobao.yunying.activitys;

import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class Act_Manager_Pwd extends HuobaoBaseActivity {

	@ViewInject(R.id.edt_old_pwd)
	private EditText edt_old_pwd;
	@ViewInject(R.id.edt_new_pwd)
	private EditText edt_new_pwd;
	@ViewInject(R.id.edt_new_re_pwd)
	private EditText edt_new_re_pwd;
	private boolean isShop = false;

	// 6-16个字符，密码必须为数字，大、小写字母或符号中的两种组合
	@Override
	protected int getContentView() {
		// TODO Auto-generated method stub
		return R.layout.layout_manager_pwd;
	}

	@Override
	protected String getTitleText() {
		return "密码管理";
	}

	@Override
	protected void init() {
		isShop = getIntent().getBooleanExtra("flag", false);
	}

	public void onSubmitClick(View view) {
		String zhegnze = "(?=.*[0-9])(?=.*[a-z])(?=.*[!@#$%^&*])(?=.*[A-Z]).{6,16}";
		String newPwd = edt_new_pwd.getText().toString().trim();
		String oldPwd = edt_old_pwd.getText().toString().trim();
		String newRePwd = edt_new_re_pwd.getText().toString().trim();
//		if (newPwd.matches(zhegnze) == false) {
//			Toast.makeText(context, "6-16个字符，密码必须为数字，大、小写字母或符号中的两种组合", Toast.LENGTH_SHORT).show();
//			return;
//		}
		if (newPwd.equals(newRePwd) == false) {
			Toast.makeText(context, "两次密码输入不一致", Toast.LENGTH_SHORT).show();
			return;
		}Map<String, String> map;
		if(isShop){
			map = HttpUtil.getParams("app", "shopmember", "act", "password", "orig_password", oldPwd,
					"new_password", newPwd, "confirm_password", newRePwd);
		}else{
			map = HttpUtil.getParams("app", "member", "act", "password", "orig_password", oldPwd,
					"new_password", newPwd, "confirm_password", newRePwd);	
		}
		 
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				Toast.makeText(context, jsonObject.getString("retval"), Toast.LENGTH_SHORT).show();
				finish();
			}
			
			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub
				
			}
		});

	}
}
